// FX_BPA.cpp: implementation of the CFX_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/FX_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFX_BPA::CFX_BPA()
{
	m_chType = 'F';
	m_chSubType = 'X';
	m_chChangeCode = ' ';

	m_dRc = 0;
	m_dXc = 0;
	m_dTr = 0;
	m_dKa = 0;
	m_dTa = 0;
	m_dKp = 0;
	m_dKi = 0;
	m_dVrMax = 0;
	m_dVrMin = 0;
	m_dIkp = 0;
	m_dIki = 0;
	m_dVfMax = 0;
	m_dVfMin = 0;
	m_dKt = 0;
	m_dTt = 0;

	m_strCardType[0] = 'F';
	m_strCardType[1] = '1';

}

CFX_BPA::CFX_BPA(CFX_BPA &fxBPA):CUnit_BPA(fxBPA)
{
	m_dRc = fxBPA.m_dRc;
	m_dXc = fxBPA.m_dXc;
	m_dTr = fxBPA.m_dTr;
	m_dKa = fxBPA.m_dKa;
	m_dTa = fxBPA.m_dTa;
	m_dKp = fxBPA.m_dKp;
	m_dKi = fxBPA.m_dKi;
	m_dVrMax = fxBPA.m_dVrMax;
	m_dVrMin = fxBPA.m_dVrMin;
	m_dIkp = fxBPA.m_dIkp;
	m_dIki = fxBPA.m_dIki;
	m_dVfMax = fxBPA.m_dVfMax;
	m_dVfMin = fxBPA.m_dVfMin;
	m_dKt = fxBPA.m_dKt;
	m_dTt = fxBPA.m_dTt;
}

CFX_BPA::~CFX_BPA()
{

}

bool CFX_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFX_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dRc = StrToDouble(&buffer[16],4,3);
	if(EndOfSec(&buffer[16],4))
		return true;

	m_dXc = StrToDouble(&buffer[20],4,3);
	if(EndOfSec(&buffer[20],4))
		return true;

	m_dTr = StrToDouble(&buffer[24],4,4);
	if(EndOfSec(&buffer[24],4))
		return true;

	m_dKa = StrToDouble(&buffer[28],4,3);
	if(EndOfSec(&buffer[28],4))
		return true;

	m_dTa = StrToDouble(&buffer[32],4,4);
	if(EndOfSec(&buffer[32],4))
		return true;

	m_dKp = StrToDouble(&buffer[36],4,3);
	if(EndOfSec(&buffer[36],4))
		return true;

	m_dKi = StrToDouble(&buffer[40],4,3);
	if(EndOfSec(&buffer[40],4))
		return true;

	m_dVrMax = StrToDouble(&buffer[44],5,3);
	if(EndOfSec(&buffer[44],5))
		return true;

	m_dVrMin = StrToDouble(&buffer[49],5,3);
	if(EndOfSec(&buffer[49],5))
		return true;

	m_dIkp = StrToDouble(&buffer[54],4,3);
	if(EndOfSec(&buffer[54],4))
		return true;

	m_dIki = StrToDouble(&buffer[58],4,3);
	if(EndOfSec(&buffer[58],4))
		return true;

	m_dVfMax = StrToDouble(&buffer[62],5,3);
	if(EndOfSec(&buffer[62],5))
		return true;

	m_dVfMin = StrToDouble(&buffer[67],5,3);
	if(EndOfSec(&buffer[67],5))
		return true;

	m_dKt = StrToDouble(&buffer[72],4,3);
	if(EndOfSec(&buffer[72],4))
		return true;

	m_dTt = StrToDouble(&buffer[76],4,4);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CFX_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFX_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dRc,&buffer[16],4,3);
	DoubleToStr(m_dXc,&buffer[20],4,3);
	DoubleToStr(m_dTr,&buffer[24],4,4);
	DoubleToStr(m_dKa,&buffer[28],4,3);
	DoubleToStr(m_dTa,&buffer[32],4,4);
	DoubleToStr(m_dKp,&buffer[36],4,3);
	DoubleToStr(m_dKi,&buffer[40],4,3);
	DoubleToStr(m_dVrMax,&buffer[44],5,3);
	DoubleToStr(m_dVrMin,&buffer[49],5,3);
	DoubleToStr(m_dIkp,&buffer[54],4,3);
	DoubleToStr(m_dIki,&buffer[58],4,3);
	DoubleToStr(m_dVfMax,&buffer[62],5,3);
	DoubleToStr(m_dVfMin,&buffer[67],5,3);
	DoubleToStr(m_dKt,&buffer[72],4,3);
	DoubleToStr(m_dTt,&buffer[76],4,4);

	return true;
}